<template>
  <div class="JADP-common-layout">
    <div class="JADP-common-layout-center">
      <el-row class="JADP-common-search-box" :gutter="16">
        <el-form @submit.native.prevent>
          <el-col :span="6">
            <el-form-item label="班级编号">
              <el-input v-model="query.clazzno" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="班级名称">
              <el-input
                v-model="query.classname"
                placeholder="请输入"
                clearable
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="search()"
                >查询</el-button
              >
              <el-button icon="el-icon-refresh-right" @click="reset()"
                >重置</el-button
              >
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="JADP-common-layout-main JADP-flex-main">
        <JADP-table
          v-loading="listLoading"
          :data="list"
          @sort-change="sortChange"
        >
          <el-table-column
            prop="clazzno"
            label="班级编号"
            align="left"
            show-overflow-tooltip
          />
          <el-table-column
            prop="classname"
            label="班级名称"
            align="left"
            show-overflow-tooltip
          />
          <el-table-column prop="categorytype" label="行业类型" align="left" />
          <el-table-column label="培训类别" prop="train_type" algin="left">
            <template slot-scope="scope">
              {{ getDict("pxlb", scope.row.train_type) }}
            </template>
          </el-table-column>
          <el-table-column label="培训方式" prop="train_mode" algin="left">
            <template slot-scope="scope">
              {{ getDict("bjpxfs", scope.row.train_mode) }}
            </template>
          </el-table-column>

          <el-table-column label="操作" fixed="right" width="100">
            <template slot-scope="scope">
              <el-button type="text" @click="addOrUpdateHandle(scope.row)"
                >档案管理
              </el-button>
            </template>
          </el-table-column>
        </JADP-table>
        <pagination
          :total="total"
          :page.sync="listQuery.currentPage"
          :limit.sync="listQuery.pageSize"
          @pagination="initData"
        />
      </div>
    </div>
    <JADP-Form v-if="formVisible" ref="JADPForm" @refresh="refresh" />
  </div>
</template>

<script>
import request from "@/utils/request";

import JADPForm from "./Form";
export default {
  components: { JADPForm },
  data() {
    return {
      query: {
        clazzno: undefined,
        classname: undefined
      },
      list: [],
      listLoading: true,
      total: 0,
      listQuery: {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      },
      formVisible: false
    };
  },
  computed: {},
  created() {
    this.initData();
  },
  methods: {
    sortChange({ column, prop, order }) {
      this.listQuery.sort = order == "ascending" ? "asc" : "desc";
      this.listQuery.sidx = !order ? "" : prop;
      this.initData();
    },
    initData() {
      this.listLoading = true;
      let _query = {
        ...this.listQuery,
        ...this.query,
        isAdmin: true,
        organizeId:this.$store.getters.organizeId
      };
      let query = {};
      for (let key in _query) {
        if (Array.isArray(_query[key])) {
          query[key] = _query[key].join();
        } else {
          query[key] = _query[key];
        }
      }
      request({
        url: `/api/xy_ks_class_info/Xy_ks_class_info`,
        method: "get",
        data: query
      }).then(res => {
        this.list = res.data.list;
        this.total = res.data.pagination.total;
        this.listLoading = false;
      });
    },
    addOrUpdateHandle(row) {
      this.formVisible = true;
      this.$nextTick(() => {
        this.$refs.JADPForm.init(row);
      });
    },
    search() {
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      };
      this.initData();
    },
    refresh(isrRefresh) {
      this.formVisible = false;
      if (isrRefresh) this.reset();
    },
    reset() {
      for (let key in this.query) {
        this.query[key] = undefined;
      }
      this.listQuery = {
        currentPage: 1,
        pageSize: 20,
        sort: "desc",
        sidx: ""
      };
      this.initData();
    }
  }
};
</script>
